<template>
  <view class="my-collect">
    <!-- 导航栏 -->
    <Header title="我的收藏"></Header>
    <!-- 背景-->
    <view class="bg"></view>

    <!-- 卡片-->
    <view class="card" v-if="collectGoods.length">
      <view class="goods_item" v-for="e in collectGoods" :key="e['pid']">
        <view class="cover" @click="gotoDetailHandler(e['pid'])">
          <image :src="e['smallImg']">
          </image>
        </view>
        <view class="name">
          {{e['name']}}
        </view>
        <view class="enname">
          {{e['enname']}}
        </view>
        <view class="price">
          <text>￥{{e['price']}}</text>
          <uni-icons type="trash" size="15" color="#b5b5b5" @click="notCollectHandler(e['pid'])"></uni-icons>
        </view>
      </view>

    </view>
    <MyEmpty v-else title="暂无收藏"></MyEmpty>
  </view>
</template>

<script>
  import MyEmpty from '../../../../components/MyEmpty/MyEmpty.vue'
  import Header from "../../../../components/HeaderNav/HeaderNav.vue"
  import {
    req
  } from "../../../utils/request/request";
  import {
    uniToast
  } from "../../../utils/uni/uni";
  export default {
    components: {
      Header,
      MyEmpty
    },
    data() {
      return {
        collectGoods: []
      };
    },
    onLoad() {
      this.getMyCollectGoods()
    },
    methods: {

      /* 跳转商品信息*/
      gotoDetailHandler(pid) {
        uni.navigateTo({
          url: '/pages/goods_detail/goods_detail?wd=' + pid
        })
      },
      /* 获取所有收藏商品*/
      getMyCollectGoods() {
        req('findAllLike', {
          isToken: true
        }).then(({
          data: res
        }) => {
          this.collectGoods = res['result']
          console.log(this.collectGoods);
        }, err => {
          console.log(err);
        })
      },
      /* 取消收藏*/
      notCollectHandler(pid) {
        req('notlike', {
          reqData: {
            pid
          },
          isToken: true,
          method: 'POST'
        }).then(({
          data: res
        }) => {
          uniToast(res['msg'])
          this.getMyCollectGoods()
        }, err => {})
      }
    }
  }
</script>

<style lang="scss" scoped>
  page {
    background-color: #f7f7f7;
  }

  .my-collect {

    .bg {
      background-color: #0c34ba;
      height: 200rpx;
    }

    .card {
      display: flex;
      flex-wrap: wrap;
      border-top-right-radius: 15rpx;
      border-top-left-radius: 15rpx;
      overflow: hidden;
      background-color: #fff;
      transform: translateY(-50rpx);
      margin: 0 30rpx;
      padding: 25rpx;
      padding-bottom: 40rpx;

      .empty-tips {
        font-size: 24rpx;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .goods_item {
        width: 33.333333%;
        margin-bottom: 30rpx;
        box-sizing: border-box;

        .cover {
          width: 200rpx;
          height: 200rpx;

          image {
            width: 100%;
            height: 100%;
          }
        }

        .name,
        .enname,
        .price {
          font-size: 25rpx;
          margin-top: 10rpx;
          width: 200rpx;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
        }

        .enname {
          color: #9a9997;
        }

        .price {
          color: #0c34ba;
          font-weight: bold;
          font-size: 28rpx;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
      }
    }

  }
</style>
